package com.he.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.he.entity.Book;
import com.he.entity.BookCategory;
import com.he.mapper.BookMapper;
import com.he.service.BookService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Resource
    private BookMapper bookMapper;

    @Override
    public List<Book> selectBookList() {
        return bookMapper.selectList(null);
    }

    @Override
    public List<BookCategory> selectBookCategoryList() {
        return bookMapper.selectBookCategoryList();
    }

    @Override
    public List<Book> selectBookPage1(int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return bookMapper.selectBookPage1(offset, pageSize);
    }

    @Override
    public List<Book> selectBookPage2(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Book> bookList = bookMapper.selectList(null);
        PageInfo<Book> pageInfo = new PageInfo<>(bookList);
        return pageInfo.getList();
    }

    @Override
    public List<Book> selectBookPage3(int pageNum, int pageSize) {
        Page<Book> page = new Page<>(pageNum, pageSize);
        Page<Book> bookPage = bookMapper.selectPage(page, null);
        return bookPage.getRecords();
    }
}
